﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Script.UI;
using UnityEngine.UI;
using XCharts;
using Script.UI.Component;
using LitJson;
using MTUnity.Utils;
using System;
using System.Linq;

public class UI_Voltage : UIUpdateBase
{


    public HistogramGroup Panel_6H;
    public HistogramGroup Panel_12H;

    public LiquidChart Liquid_Voltage;

    public Text Txt_RefreshTime;

    #region Interface
    public override Dictionary<string, UpdateDel> RegisterProcessorMethod()
    {
        return new Dictionary<string, UpdateDel>
        {
            {JsonFildName.OverView.Current_Voltage , UpdateCurrentVoltage },
            {JsonFildName.OverView.Record_Voltage , UpdateRecordVoltage },
            {JsonFildName.OverView.VoltageRefreshTime , UpdateRefreshTime },
        };
    }
    #endregion

    #region UpdateInterface
    public void UpdateCurrentVoltage(JsonData jsonData)
    {
        UpdateCurrentVoltage(JsonUtils.ToDouble(jsonData));
    }

    public void UpdateRecordVoltage(JsonData jsonData)
    {
        if (jsonData.IsArray)
        {
            List<HistogramDataBase> listData = Utils.SetData<HistogramData_Voltage>(jsonData, JsonFildName.OverView.Voltage);
            UpdateRecordVoltage(listData);
        }
    }

    public void UpdateRefreshTime(JsonData jsonData)
    {
        UpdateRefreshTime(JsonUtils.ToLong(jsonData));
    }
    #endregion

    public void UpdateCurrentVoltage(double dVoltage)
    {
        Liquid_Voltage.UpdateData(0, 0, (float)dVoltage);
    }

    public void UpdateRecordVoltage(List<HistogramDataBase> listData)
    {
        Panel_6H.Refresh(listData);
        Panel_12H.Refresh(listData);
    }

    public void UpdateRefreshTime(long lRefreshTime)
    {
        DateTime datatime = TimeUtil.FromTimestamp(lRefreshTime);
        Txt_RefreshTime.text = string.Format("数据更新 {0}", datatime.ToString("{yyyy-MM-dd HH:mm:ss}"));
    }

}